package com.gm.service.user;

import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import com.github.miemiedev.mybatis.paginator.domain.PageList;
import com.gm.common.Pager;
import com.gm.dao.rate.IRateDao;
import com.gm.model.po.Rate;
import com.gm.tools.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 费率服务层
 * Created by Administrator on 2017/6/25.
 */

@Service
public class RateService {

    @Autowired
    private IRateDao rateDao;


    public PageList<Rate> getRateList(Pager pager){
        PageBounds pageBounds = new PageBounds(pager.getCurrentPage(), pager.getPageSize());
        return rateDao.getRateList(pageBounds);
    }

    public List<Rate> getRateAll(){
        return rateDao.getRateAll();
    }

    public int addRate(Rate rate){
        rate.setStatus(1);
        rate.setCreateTime(DateUtils.getCurrentUnixTime());
        rate.setUpdateTime(DateUtils.getCurrentUnixTime());
        return rateDao.insert(rate);
    }

    public int updateRate(Rate rateParm){
        Rate  rate = rateDao.selectByPrimaryKey(rateParm.getId());
        rate.setRate(rateParm.getRate());
        rate.setRemark(rateParm.getRemark());
        rate.setUpdateTime(DateUtils.getCurrentUnixTime());
        return rateDao.updateByPrimaryKey(rate);
    }

    public int deleteRate(Integer rateId){
        Rate  rate = rateDao.selectByPrimaryKey(rateId);
        rate.setStatus(0);
        return rateDao.updateByPrimaryKey(rate);
    }

    public Rate selectByPrimaryKey(Integer id){
        return rateDao.selectByPrimaryKey(id);
    }
}
